<!--
 * @Description:: 请补充填写
 * @Version: 1.0
 * @Author: 小白
 * @Date: 2022-04-14 14:26:46
 * @LastEditors: 小白
 * @LastEditTime: 2025-11-10 15:07:46
 * @FilePath: \jzadmin\src\views\home\components\list.vue
-->

<template>
  <SearchForm @search="searchFun" :houseList="houseList" style="margin-bottom: 20px" />
  <el-card class="page_card" shadow="never">
    <template #header>
      <div class="card-header">
        <div class="left">
          轮播图管理
         
            <el-button style="margin-left: 20px" type="primary" @click="add('新增用户')">
              新增用户
            </el-button>
        </div>
        <div class="right">
          <el-button circle @click="refreshFun">
            <i class="icon ion-refresh" :class="iconRefresh" />
          </el-button>
        </div>
      </div>
    </template>
    <Table :table-data="tableData" :table-columns="columns" :page-size="pageSize" :page-num="pageNum" :loading="loading"
      :total="total" @edit="edit" @remark="remark" @selectionChange="selectionChange" @change="changePage"
      @ok="getData()" />
    <Modal @ok="getData()" ref="modalRef"></Modal>
  </el-card>
</template>
<script lang="ts" setup>
import { REQUEST } from '@/api/request'
import { ElMessage, ElMessageBox } from 'element-plus'
import SearchForm from './search.vue'
import Table from './table.vue'
import Modal from './modal.vue'
import { onMounted, ref } from 'vue'

const iconRefresh = ref('')
const pageNum = ref(1)
const pageSize = ref(10)
import { store } from '@/store'
const total = ref(0)
const modalRef = ref(null)
const loading = ref(false)
const tableData = ref([])
const columns = ref([
 {
  title:'图片',
  prop:'img',
  align:'center',
  isShow:true,
  minwidth:'180',
 },
 {
  title:'状态',
  prop:'status',
  align:'center',
  isShow:true,
 },
  {
    title: '创建时间',
    prop: 'createTime',
    align: 'center',
    modifiable: true,
    isShow: true,
    minwidth: '180'
  },
  {
    title: '操作',
    prop: 'action',
    align: 'center',
    modifiable: true,
    isShow: true,
    minwidth: '180'
  }
])
onMounted(() => {
  getHouseList()
  getData()
})
const houseList = ref([])
const getHouseList = () => {
  REQUEST.POST('GETHOUSELIST', {}).then((res: any) => {
    console.log(res.data)
    houseList.value = res.data.map((item: any) => ({ id: item.id, houseName: item.houseName }))
  })
}
const add = (title: string) => {
  modalRef.value.openModal('新增', houseList.value)
}


const getData = () => {
  // loading.value = true
  REQUEST.POST('USERLIST', { ...queryForm.value, pageNumber: pageNum.value, pageSize: pageSize.value }).then((res: any) => {
    tableData.value = res.data.records
    total.value = res.total
  })
}
const modalRefYhq = ref()
const refreshFun = () => {
  iconRefresh.value = 'iconRefresh'
  getData()
  setTimeout(() => {
    iconRefresh.value = ''
  }, 1000)
}
const queryForm = ref({})
const searchFun = (e: any) => {
  queryForm.value = e
  getData()
}
const selectList = ref([])
const selectionChange = (e: any) => {
  selectList.value = e
}

const edit = () => {
  modalRef.value.openModal('编辑', selectList.value[0])
}
const changePage = (e: any) => {
  pageNum.value = e.pageNum
  pageSize.value = e.pageSize
  getData()
}
</script>

<style lang="scss" scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
